#ifndef BACKUPTABLE_H
#define BACKUPTABLE_H

#include <QWidget>
#include "backuprecorditem.h"
#include <QPropertyAnimation>
#include <QVector>
#include <QVBoxLayout>
#include <qscrollbar.h>

namespace Ui {
class BackupTable;
}

class BackupTable : public QWidget
{
    Q_OBJECT

public:
    explicit BackupTable(QWidget *parent = nullptr);
    ~BackupTable();

    QVector<BackupRecordItem*> getSelectedRecords() const;
    void selectAll();
    void deselectAll();

    void scrollToItem(qint64 fileId);
    void scrollToItem(QString fileName);
protected:
    void paintEvent(QPaintEvent *event) override;
signals:
    void refreshData();
public slots:
    void deleteAllSelected();
    void downloadAllSelected();

    void appendRecord(const FileInfo& recordInfo);
    void updateItemStatus(int file_id);

    void deleteRecord(BackupRecordItem* recordItem);
private:
    Ui::BackupTable *ui;
    QVector<BackupRecordItem*> m_selectedRecords;
    QVBoxLayout *m_layout = nullptr;
    QPropertyAnimation *m_animation = nullptr;
    QMap<int64_t, BackupRecordItem*> m_downloadRecords;

    void scrollToWidget(QWidget* target);
};

#endif // BACKUPTABLE_H
